import 'package:flutter/material.dart';
import 'package:flutter_chip/config/Comm.dart';

class Progress extends StatefulWidget {
  int progress;
  String type;

  Progress(this.progress, this.type);

  @override
  _ProgressState createState() => _ProgressState();
}

class _ProgressState extends State<Progress> {
  @override
  void initState() {
    super.initState();
    print("当前状态：${widget.progress}");
  }

  @override
  Widget build(BuildContext context) {
    String step1 = "已拍下", step2 = "未付款", step3 = "未发货", step4 = "待收货";
    if (widget.progress == 0) {
      step1 = "已拍下";
    } else if (widget.progress == 1) {
      step1 = "已拍下";
      step2 = "已付款";
    } else if (widget.progress == 2) {
      step2 = "已付款";
      step3 = "已发货";
    } else if (widget.progress == 3) {
      step2 = "已付款";
      step3 = "已发货";
      step4 = "交易成功";
    } else if (widget.progress == 6) {
      step2 = "未付款";
      step3 = "未发货";
      step4 = "交易关闭";
    } else {
      step2 = "已付款";
      step3 = "已发货";
      step4 = "退款中";
    }

    return Container(
      width: Comm.screenWidth,
      padding: EdgeInsets.only(left: 10, right: 10),
      child: Stack(
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Container(width: 20),
              Expanded(child: _divWidget(0)),
              Container(width: 20),
              Expanded(child: _divWidget(1)),
              Container(width: 20),
              Expanded(child: _divWidget(2)),
              Container(width: 20),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              _itemPointWidget(0, step1),
              _itemPointWidget(1, step2),
              _itemPointWidget(2, step3),
              _itemPointWidget(3, step4),
            ],
          ),
        ],
      ),
    );
  }

  ///中间横线
  Widget _divWidget(int index) {
    Color color = Color(0xffdddddd);
    if (index < widget.progress) {
      color = Color(0XFFFEDB43);
    }
    return Container(
      height: 2,
      margin: EdgeInsets.only(top: 15),
      color: color,
    );
  }

  Widget _itemPointWidget(int index, String step) {
    double radius = 20;
    Color color = Color(0XFFFCF3C6);
    if (index > widget.progress) {
      color = Colors.transparent;
      radius = 10;
    }
    return Column(
      children: <Widget>[
        Container(
          width: 30,
          height: 30,
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color: color,
            borderRadius: BorderRadius.circular(20),
          ),
          child: Container(
            width: radius,
            height: radius,
            alignment: Alignment.center,
            decoration: BoxDecoration(
              color: Color(0XFFFEDB43),
              borderRadius: BorderRadius.circular(15),
            ),
            child: Offstage(
              offstage: widget.progress < index,
              child: Icon(
                Icons.check,
                size: 16,
              ),
            ),
          ),
        ),
        _itemTextWidget(index, step),
      ],
    );
  }

  Widget _itemTextWidget(int index, String step) {
    Color color = Color(0XFF333333);
    FontWeight fontWeight = FontWeight.w600;
    if (index > widget.progress) {
      color = Colors.grey;
      fontWeight = FontWeight.w400;
    }
    return Text(
      step,
      style: TextStyle(
        fontWeight: fontWeight,
        color: color,
      ),
    );
  }
}
